package com.uniledger.exchange.home.scheme.fragment.topup;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.TextView;

import com.uniledger.exchange.R;
import com.uniledger.exchange.model.HttpResult;
import com.uniledger.exchange.model.OkSingleton;
import com.uniledger.exchange.model.StellarAsset;
import com.uniledger.exchange.model.api.Api;
import com.uniledger.exchange.model.rx.RxException;
import com.uniledger.exchange.model.rx.RxProgress;
import com.uniledger.exchange.model.rx.RxSchedulers;

import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;
import io.reactivex.functions.Consumer;

/**
 *
 */
public class IntoOkFragment extends TopUpFragment {

    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";

    private String mParam1;
    private String mParam2;

    @BindView(R.id.txt_balance)
    TextView txt_balance;

    @BindView(R.id.txt_category)
    TextView txt_category;

    @BindView(R.id.txt_remark)
    TextView txt_remark;

    @BindView(R.id.txt_amount)
    TextView txt_amount;

    public IntoOkFragment() {
        // Required empty public constructor
    }


    public static IntoOkFragment newInstance(String param1, String param2) {
        IntoOkFragment fragment = new IntoOkFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        Api.getService().getBalance()
                .compose(RxSchedulers.io_main())
                .compose(RxProgress.applyProgressBar(getActivity()))
                .subscribe(new Consumer<HttpResult<List<StellarAsset>>>() {
                    @Override
                    public void accept(HttpResult<List<StellarAsset>> httpResult) throws Exception {
                        StellarAsset asset=httpResult.data.get(0);


                    }
                }, new RxException<>(new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {

                    }
                }));
        txt_balance.setText(OkSingleton.getInstance().getAssetBalance());
        txt_category.setText(OkSingleton.getInstance().getCurrencyCode());
        txt_amount.setText(mParam1);
        txt_remark.setText(mParam2);
    }

    @Override
    public void onClick(View v) {
        listener.topUpOk();
    }

    @Override
    public int getViewResourceId() {
        return R.layout.fragment_into_ok;
    }
}
